<!-- 开始节点配置 -->
<template>
  <el-form
    label-width="96px"
    label-position="left"
    size="mini"
    class="wf-collapse-form"
  >
    <el-collapse v-model="activeNames">
      <el-collapse-item :title="$t('基础配置')" name="1">
        <div style="padding: 0 16px">
          <el-form-item :label="$t('节点标识')">
            <el-input v-model="node.id" readonly></el-input>
          </el-form-item>
          <el-form-item :label="$t('继承表单')">
            <el-switch :disabled="disabled" v-model="node.isInherit">
            </el-switch>
          </el-form-item>

          <el-form-item :label="$t('允许加签')">
            <el-switch :disabled="disabled" v-model="node.isAddSign">
            </el-switch>
          </el-form-item>
          <el-form-item :label="$t('允许转移')">
            <el-switch :disabled="disabled" v-model="node.isTransfer">
            </el-switch>
          </el-form-item>
          <el-form-item :label="$t('驳回校验表单')">
            <el-switch :disabled="disabled" v-model="node.rejectNeedForm">
            </el-switch>
          </el-form-item>
          <el-form-item :label="$t('再审到驳回点')">
            <el-switch :disabled="disabled" v-model="node.isRejectBackOld">
            </el-switch>
          </el-form-item>
          <el-form-item :label="$t('允许批量审核')">
            <el-switch :disabled="disabled" v-model="node.isBatchAudit">
            </el-switch>
          </el-form-item>
          <el-form-item :label="$t('允许上传附件')">
            <el-switch :disabled="disabled" v-model="node.isUploadFile">
            </el-switch>
          </el-form-item>


          <el-form-item :label="$t('自动同意规则')">
            <l-select
              multiple
              :disabled="disabled"
              v-model="node.autoAgree"
              :options="atuoAgreeOptions"
            >
            </l-select>
          </el-form-item>
          <el-form-item :label="$t('无对应处理人')">
            <l-select
              :disabled="disabled"
              v-model="node.noAuditor"
              :options="showNoAuditorOptions"
            >
            </l-select>
          </el-form-item>
          <el-form-item :label="$t('驳回策略')">
            <l-radio
              :disabled="disabled"
              v-model="node.rejectType"
              :options="[
                { value: '1', label: this.$t('驳回节点固定') },
                { value: '2', label: this.$t('能驳回到任何执行过节点') },
              ]"
            >
            </l-radio>
          </el-form-item>



          <el-form-item :label="$t('通知策略')">
            <l-checkbox
              :disabled="disabled"
              v-model="node.messageType"
              :options="[
                { value: '1', label: this.$t('短信') },
                { value: '2', label: this.$t('邮箱') },
                { value: '3', label: this.$t('微信') },
                { value: '4', label: this.$t('站内消息') },
              ]"
            >
            </l-checkbox>
          </el-form-item>
        </div>
      </el-collapse-item>
      <el-collapse-item :title="$t('审核人员设置')" name="2">
        <el-button-group style="padding: 0 0 8px 8px" v-if="!disabled">
          <el-button size="mini" @click="handlePostClick('auditor')">{{
            $t("岗位")
          }}</el-button>
          <el-button size="mini" @click="handleRoleClick('auditor')">{{
            $t("角色")
          }}</el-button>
          <el-button size="mini" @click="handleUserClick('auditor')">{{
            $t("用户")
          }}</el-button>
          <el-button size="mini" @click="handleLevelClick('auditor')">{{
            $t("上下级")
          }}</el-button>
          <el-button size="mini" @click="handleNodeAuditorClick('auditor')">{{
            $t("节点执行人")
          }}</el-button>
          <el-button size="mini" @click="handleAuditorSqlClick('auditor')">{{
            $t("表字段")
          }}</el-button>
          <!--<el-button size="mini" @click="handleAuditorOtherAPIClick('auditor')">{{
            $t("第三方")
          }}</el-button>-->
        </el-button-group>
        <l-edit-table
          :isAddBtn="false"
          @deleteRow="handleTableBtnClick"
          :columns="userColumns"
          :dataSource="node.auditUsers"
        >
          <template v-slot:type="scope">
            {{ typeFormat(scope.row.type) }}
          </template>
          <template v-slot:condition="scope">
            <l-select
              :disabled="disabled"
              size="mini"
              v-if="scope.row.type == '2'"
              :options="conditionOptions"
              v-model="scope.row.condition"
            ></l-select>
          </template>
        </l-edit-table>
      </el-collapse-item>
      <el-collapse-item :title="$t('传阅人员设置')" name="3">
        <el-button-group style="padding: 0 0 8px 8px" v-if="!disabled">
          <el-button size="mini" @click="handlePostClick('looker')">{{
            $t("岗位")
          }}</el-button>
          <el-button size="mini" @click="handleRoleClick('looker')">{{
            $t("角色")
          }}</el-button>
          <el-button size="mini" @click="handleUserClick('looker')">{{
            $t("用户")
          }}</el-button>
          <el-button size="mini" @click="handleLevelClick('looker')">{{
            $t("上下级")
          }}</el-button>
          <el-button size="mini" @click="handleNodeAuditorClick('looker')">{{
            $t("节点执行人")
          }}</el-button>
          <el-button size="mini" @click="handleAuditorSqlClick('looker')">{{
            $t("表字段")
          }}</el-button>
          <el-button size="mini" @click="handleAuditorOtherAPIClick('looker')">{{
            $t("第三方")
          }}</el-button>
        </el-button-group>
        <l-edit-table
          :isAddBtn="false"
          @deleteRow="handleTableBtnClick2"
          :columns="userColumns"
          :dataSource="node.lookUsers"
        >
          <template v-slot:type="scope">
            {{ typeFormat(scope.row.type) }}
          </template>
          <template v-slot:condition="scope">
            <l-select
              :disabled="disabled"
              size="mini"
              v-if="scope.row.type == '2'"
              :options="conditionOptions"
              v-model="scope.row.condition"
            ></l-select>
          </template>
        </l-edit-table>
      </el-collapse-item>
      <el-collapse-item v-if="!node.isInherit" :title="$t('表单设置')" name="4">
        <div style="padding: 0 16px">
          <div style="text-align: center; margin-bottom: 16px">
            <el-radio-group
              :disabled="disabled"
              v-model="node.formType"
              size="mini"
              @change="handleFormTypeChange"
            >
              <el-radio-button label="1">{{ $t('自定义表单') }}</el-radio-button>
              <el-radio-button label="2">{{ $t('系统表单') }}</el-radio-button>
            </el-radio-group>
          </div>
          <el-form-item label-width="0px">
            <l-wordprint-select
              v-model="node.formWrodPrintCode"
              :placeholder="$t('选择打印Word模版')"
              :disabled="disabled"
            />
          </el-form-item>
          <div v-show="node.formType === '1'">
            <el-form-item label-width="0px">
              <l-custmerform-select
                v-model="node.formCode"
                @change="custmerformChange"
                :disabled="disabled"
              >
              </l-custmerform-select>
            </el-form-item>
            <el-form-item label-width="0px">
              <l-select
                v-model="node.formVerison"
                :disabled="disabled"
                :options="formVerisons"
                @change="custmerformVerisonChange"
                :placeholder="$t('请选择表单版本')"
              >
              </l-select>
            </el-form-item>
            <el-form-item label-width="0px">
              <l-select
                v-model="node.formRelationId"
                :disabled="disabled"
                :options="node.formRelations"
                :placeholder="$t('请选择流程关联字段')"
              >
              </l-select>
            </el-form-item>
          </div>
          <div v-show="node.formType === '2'">
            <el-form-item label-width="0px">
              <el-input
                v-model="node.formUrl"
                :placeholder="$t('请输入PC端表单地址')"
                :readonly="disabled"
              >
              </el-input>
            </el-form-item>
            <el-form-item label-width="0px">
              <el-input
                v-model="node.formAppUrl"
                :placeholder="$t('请输入APP端表单地址')"
                :readonly="disabled"
              >
              </el-input>
            </el-form-item>
          </div>
          <el-divider>{{ $t('表单字段权限') }}</el-divider>
          <template v-if="node.formType === '1'">
            <l-table
              height="notset"
              :isShowNum="false"
              :columns="columns"
              :dataSource="node.authFields"
              ref="authField"
            >
              <template v-slot:required="scope">
                <el-switch
                  v-model="scope.row.required"
                  :disabled="disabled || scope.row.type == 'grid'"
                >
                </el-switch>
              </template>
              <template v-slot:isEdit="scope">
                <el-switch
                  v-model="scope.row.isEdit"
                  :disabled="disabled || scope.row.type == 'gridrequired'"
                >
                </el-switch>
              </template>
              <template v-slot:isLook="scope">
                <el-switch
                  v-model="scope.row.isLook"
                  :disabled="
                    disabled ||
                      scope.row.type == 'grid' ||
                      scope.row.type == 'gridrequired'
                  "
                >
                </el-switch>
              </template>
            </l-table>
          </template>
          <template v-else>
            <l-edit-table
              :addBtnText="$t('添加字段')"
              :dataSource="node.authFields"
              :isAddBtn="!disabled"
              :isRemoveBtn="!disabled"
              @addRow="handleAddAuthField"
              @deleteRow="handleDeleteAuthField"
            >
              <el-table-column prop="label" :label="$t('名称')" minWidth="100">
                <template slot-scope="scope">
                  <el-input
                    :readonly="disabled"
                    size="mini"
                    v-model="scope.row.label"
                    :placeholder="$t('请输入名称')"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="field" :label="$t('字段')" minWidth="100">
                <template slot-scope="scope">
                  <el-input
                    :readonly="disabled"
                    size="mini"
                    v-model="scope.row.field"
                    :placeholder="$t('请输入字段')"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="required" :label="$t('必填')" width="64">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.required" :disabled="disabled">
                  </el-switch>
                </template>
              </el-table-column>
              <el-table-column prop="isEdit" :label="$t('编辑')" width="64">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.isEdit" :disabled="disabled">
                  </el-switch>
                </template>
              </el-table-column>
              <el-table-column prop="isLook" :label="$t('查看')" width="64">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.isLook" :disabled="disabled">
                  </el-switch>
                </template>
              </el-table-column>
            </l-edit-table>
          </template>
        </div>
      </el-collapse-item>
      <el-collapse-item :title="$t('按钮设置')" name="5">
        <l-edit-table
          :addBtnText="$t('添加按钮')"
          :dataSource="node.btnlist"
          :hasDeleteBtn="hasBtnsDeleteBtn"
          :isAddBtn="!disabled && !node.isCountersign"
          :isRemoveBtn="!disabled"
          @addRow="handleAddBtns"
          @deleteRow="handleDeleteBtns"
          :filterDeleteBtn="filterDeleteBtn"
        >
          <el-table-column prop="name" :label="$t('名称')" minWidth="100">
            <template slot-scope="scope">
              <el-input
                :readonly="disabled"
                v-if="!scope.row.isSys || node.isCountersign"
                size="mini"
                v-model="scope.row.name"
                :placeholder="$t('请输入名称')"
              ></el-input>
              <span v-else>{{ scope.row.name }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="code" :label="$t('编码')" minWidth="100">
            <template slot-scope="scope">
              <el-input
                :readonly="disabled"
                v-if="!scope.row.isSys"
                size="mini"
                v-model="scope.row.code"
                :placeholder="$t('请输入编码')"
              ></el-input>
              <span v-else>{{ scope.row.code }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="hidden" :label="$t('隐藏')" width="64">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.hidden" :disabled="disabled">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="isSign" :label="$t('签章')" width="64">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.isSign" :disabled="disabled">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="isNextAuditor"
            :label="$t('下一审核人')"
            width="80"
          >
            <template slot-scope="scope">
              <el-switch
                v-if="scope.row.code != 'disagree'"
                v-model="scope.row.isNextAuditor"
                :disabled="disabled"
              >
              </el-switch>
            </template>
          </el-table-column>
        </l-edit-table>
      </el-collapse-item>
      <el-collapse-item :title="$t('会签设置')" name="6">
        <div style="padding: 0 16px">
          <el-form-item :label="$t('是否会签')">
            <el-switch v-model="node.isCountersign" @change="countersignChange" :disabled="disabled">
            </el-switch>
          </el-form-item>
          <template v-if="node.isCountersign">
            <el-form-item :label="$t('审核方式')">
              <l-radio
                :disabled="disabled"
                v-model="node.countersignType"
                :options="[
                  { value: '1', label: this.$t('并行') },
                  { value: '2', label: this.$t('串行') },
                ]"
              >
              </l-radio>
            </el-form-item>
            <el-form-item v-if="node.countersignType == '1'" :label="$t('是否等待')"
              ><!--并行才有这个设置-->
              <el-switch v-model="node.isCountersignAll" :disabled="disabled">
              </el-switch>
            </el-form-item>
            <el-form-item v-if="node.countersignType == '1'" :label="$t('通过百分比')">
              <el-input-number
                :disabled="disabled"
                :min="1"
                :max="100"
                v-model="node.countersignAllType"
              >
              </el-input-number>
            </el-form-item>

            <el-form-item :label="$t('再次审核')">
              <l-radio
                :disabled="disabled"
                v-model="node.countersignAgian"
                :options="[
                  { value: '1', label: this.$t('已同意不需要审核') },
                  { value: '2', label: this.$t('已同意需要审核') },
                ]"
              >
              </l-radio>
            </el-form-item>
          </template>
        </div>
      </el-collapse-item>
      <el-collapse-item :title="$t('超时设置')" name="7">
        <div style="padding: 0 16px">
          <el-form-item :label="$t('超时通知')">
            <el-switch :disabled="disabled" v-model="node.isOvertimeMessage">
            </el-switch>
          </el-form-item>
          <template v-if="node.isOvertimeMessage">
            <el-form-item :label="$t('首次通知(时)')">
              <el-input-number
                :disabled="disabled"
                :min="1"
                v-model="node.overtimeMessageStart"
              >
              </el-input-number>
            </el-form-item>
            <el-form-item :label="$t('通知间隔(时)')">
              <el-input-number
                :disabled="disabled"
                :min="1"
                v-model="node.overtimeMessageInterval"
              >
              </el-input-number>
            </el-form-item>
            <el-form-item :label="$t('通知策略')">
              <l-checkbox
                :disabled="disabled"
                v-model="node.overtimeMessageType"
                :options="[
                  { value: '1', label: this.$t('短信') },
                  { value: '2', label: this.$t('邮箱') },
                  { value: '3', label: this.$t('微信') },
                  { value: '4', label: this.$t('站内消息') },
                ]"
              >
              </l-checkbox>
            </el-form-item>
          </template>
          <el-form-item :label="$t('超时流转')">
            <el-switch :disabled="disabled" v-model="node.isOvertimeGo">
            </el-switch>
          </el-form-item>
          <template v-if="node.isOvertimeGo">
            <el-form-item :label="$t('超时流转(时)')">
              <el-input-number
                :disabled="disabled"
                :min="1"
                v-model="node.overtimeGo"
              >
              </el-input-number>
            </el-form-item>
          </template>
        </div>
      </el-collapse-item>
    </el-collapse>

    <l-dialog
      :title="$t('添加岗位')"
      :visible.sync="selectPostVisible"
      :height="480"
      width="1024px"
      @ok="handlePostSelectOk"
      @closed="handlePostSelectClosed"
    >
      <l-post-select-panel ref="postSelectPanel"></l-post-select-panel>
    </l-dialog>

    <l-dialog
      :title="$t('添加角色')"
      :visible.sync="selectRoleVisible"
      :height="480"
      width="800px"
      @ok="handleRoleSelectOk"
      @closed="handleRoleSelectClosed"
    >
      <l-role-select-panel ref="roleSelectPanel"></l-role-select-panel>
    </l-dialog>

    <l-dialog
      :title="$t('添加用户')"
      :visible.sync="selectUserVisible"
      :height="480"
      width="1024px"
      @ok="handleUserSelectOk"
      @closed="handleUserSelectClosed"
    >
      <l-user-select-panel ref="userSelectPanel"></l-user-select-panel>
    </l-dialog>

    <!--上下级选择-->
    <l-dialog
      :title="$t('上下级选择')"
      :visible.sync="levelVisible"
      :height="200"
      width="500px"
      @ok="handleLevelOk"
      @closed="handleLevelClosed"
    >
      <auditor-level-form ref="auditorLevelForm"></auditor-level-form>
    </l-dialog>

    <!--流程节点选择-->
    <l-dialog
      :title="$t('流程节点选择')"
      :visible.sync="nodeAuditorVisible"
      :height="200"
      width="500px"
      @ok="handleNodeAuditorOk"
      @closed="handleNodeAuditorClosed"
      @opened="handleNodeAuditorOpened"
    >
      <node-auditor-form ref="nodeAuditorForm"></node-auditor-form>
    </l-dialog>

    <!--数据表字段选择-->
    <l-dialog
      :title="$t('数据表字段选择')"
      :visible.sync="auditorSqlVisible"
      width="500px"
      :height="300"
      @ok="handleAuditorSqlOk"
      @closed="handleAuditorSqlClosed"
    >
      <auditor-sql-form ref="auditorSqlForm"></auditor-sql-form>
    </l-dialog>

    <!--第三方-->
    <l-dialog
      :title="$t('第三方接口限制')"
      :visible.sync="auditorOtherAPIVisible"
      :height="200"
      width="500px"
      @ok="handleAuditorOtherAPIOk"
      @closed="handleAuditorOtherAPIClosed"
      @opened="handleAuditorOtherAPIOpened"
    >
      <auditor-otherapi-form ref="auditorOtherAPIForm"></auditor-otherapi-form>
    </l-dialog>
  </el-form>
</template>

<script>
const apiForm = window.$api.custmerForm.scheme;
const apiWFScheme = window.$api.workflow.scheme;

import auditorLevelForm from "./auditorLevel";
import nodeAuditorForm from "./auditorNode";
import auditorSqlForm from "./auditorSql";
import auditorOtherapiForm from "./auditorOtherapi.vue";

export default {
  name: "user-task-option",
  props: {
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  components: {
    auditorLevelForm,
    nodeAuditorForm,
    auditorSqlForm,
    auditorOtherapiForm,
  },
  data() {
    return {
      activeNames: ["1"],
      columns: [
        { label: "名称", prop: "label", minWidth: "100" },
        { label: "字段", prop: "field", minWidth: "100" },
        { label: "必填", prop: "required", width: "64", align: "center" },
        { label: "编辑", prop: "isEdit", width: "64", align: "center" },
        { label: "查看", prop: "isLook", width: "64", align: "center" },
      ],
      tableBtns: [{ prop: "Delete", label: "删除" }],
      atuoAgreeOptions: [
        { value: "1", label: this.$t("处理人就是提交人") },
        { value: "2", label: this.$t("处理人和上一步的处理人相同") },
        { value: "3", label: this.$t("处理人审批过") },
      ],
      noAuditorOptions: [
        { value: "1", label:this.$t( "超级管理员处理") },
        { value: "2", label: this.$t("跳过此步骤") },
        { value: "3", label: this.$t("不能提交") },
        { value: "4", label: this.$t("退回到发起节点") },
      ],
      userColumns: [
        { label: this.$t("类型"), prop: "type", width: "64" },
        { label: this.$t("名称"), prop: "name", minWidth: "100" },
        { label: this.$t("附加条件"), prop: "condition", minWidth: "100" },
      ],

      conditionOptions: [
        { value: "1", label: this.$t("同一个部门") },
        { value: "2", label: this.$t("同一个公司") },
        { value: "3", label: this.$t("发起人上级") },
        { value: "4", label: this.$t("发起人下级") },
      ],

      selectPostVisible: false,
      selectRoleVisible: false,
      selectUserVisible: false,
      levelVisible: false,
      nodeAuditorVisible: false,
      auditorSqlVisible: false,
      auditorOtherAPIVisible: false,

      isLooker: false,
      isAuditor: false,
      isPointer: false,
    };
  },
  asyncComputed: {
    formVerisons: {
      async get() {
        let res = [];
        if (
          !this.$validatenull(this.node.formCode) &&
          this.node.formType == "1"
        ) {
          res = await this.$awaitWraper(
            apiForm.getHistoryList(this.node.formCode)
          );
        }
        return (res || []).map((t) => {
          return { label: this.lr_dateFormat(t.f_CreateDate), value: t.f_Id };
        });
      },
    },
  },
  computed: {
    node() {
      return this.wfdesign.currentWfNode;
    },
    showNoAuditorOptions() {
      if (this.appConfig.notShowAdmin) {
        return this.noAuditorOptions.filter((t) => t.value != "1");
      } else {
        return this.noAuditorOptions;
      }
    },
  },
  inject: ["wfdesign"],
  methods: {
    async custmerformChange(val) {
      this.$set(this.node, "formRelationId", "");
      if (val == null) {
        this.node.authFields = [];
        this.node.formVerison = "";
        return;
      }
      if (
        this.$validatenull(this.wfdesign.custmerformSchemes[val.f_SchemeId])
      ) {
        const { f_SchemeInfoId, f_Scheme, f_Id } =
          (await this.$awaitWraper(apiForm.getHistory(val.f_SchemeId))) || {};
        this.wfdesign.custmerformSchemes[f_Id] = { f_Scheme };
        if (this.node.formCode == f_SchemeInfoId) {
          this.loadFormScheme(f_Scheme);
        }
      } else {
        this.loadFormScheme(
          this.wfdesign.custmerformSchemes[val.f_SchemeId].f_Scheme
        );
      }
      this.node.formVerison = val.f_SchemeId;
    },
    async custmerformVerisonChange(val) {
      this.$set(this.node, "formRelationId", "");
      if (this.$validatenull(val)) {
        this.node.authFields = [];
        return;
      }
      if (this.$validatenull(this.wfdesign.custmerformSchemes[val.value])) {
        const { f_Scheme, f_Id } =
          (await this.$awaitWraper(apiForm.getHistory(val.value))) || {};
        this.wfdesign.custmerformSchemes[f_Id] = { f_Scheme };
        if (this.node.formVerison == f_Id) {
          this.loadFormScheme(f_Scheme);
        }
      } else {
        this.loadFormScheme(
          this.wfdesign.custmerformSchemes[val.value].f_Scheme
        );
      }
    },
    loadFormScheme(strScheme) {
      const scheme = JSON.parse(strScheme);
      const fields = [];
      const rfields = [];
      scheme.formInfo.tabList.forEach((tab) => {
        tab.components.forEach((component) => {
          if (["guid"].includes(component.type)) {
            rfields.push({ label: component.label, value: component.prop });
          }

          if (
            !["gridtable", "divider"].includes(component.type) &&
            component.display
          ) {
            fields.push({
              prop: component.prop,
              field: component.field,
              label: component.label,
              table: component.table,
              required: component.required,
              isEdit: true,
              isLook: true,
            });
          } else if (
            ["divider"].includes(component.type) &&
            component.display
          ) {
            fields.push({
              prop: component.prop,
              label: `分割线-${component.label}`,
              required: false,
              isEdit: false,
              isLook: true,
            });
          } else if (["gridtable"].includes(component.type)) {
            fields.push({
              prop: `${component.prop}_add`,
              label: `${component.label || this.$t("表格")}-${this.$t("添加按钮")}`,
              required: false,
              isEdit: true,
              isLook: false,
              type: "grid",
            });
            fields.push({
              prop: `${component.prop}_remove`,
              label: `${component.label || this.$t("表格")}-${this.$t("删除按钮")}`,
              required: false,
              isEdit: true,
              isLook: false,
              type: "grid",
            });

            fields.push({
              prop: `${component.prop}_required`,
              label: `${component.label || this.$t("表格")}-${this.$t("数据")}`,
              required: component.required,
              isEdit: false,
              isLook: false,
              type: "gridrequired",
            });
            fields.push(
              ...component.children
                .filter((t) => t.display)
                .map((t) => {
                  return {
                    gridprop: component.prop,
                    prop: t.prop,
                    field: t.field,
                    label: `${component.label || this.$t("表格")}-${t.label}`,
                    table: component.table,
                    required: t.required,
                    isEdit: true,
                    isLook: true,
                  };
                })
            );
          }
        });
      });
      this.node.formRelations = rfields;
      this.node.authFields = fields;
    },
    handleFormTypeChange() {
      this.node.formCode = "";
      this.node.formUrl = "";
      this.node.formAppUrl = "";
      this.node.authFields = [];
      this.node.formRelations = [];

      this.$set(this.node, "formRelationId", "");
    },
    handleAddAuthField() {
      this.node.authFields.push({
        field: "",
        label: "",
        required: true,
        isEdit: true,
        isLook: true,
      });
    },
    handleDeleteAuthField(row) {
      this.node.authFields.splice(row.index, 1);
    },

    handleTableBtnClick({ index }) {
      this.node.auditUsers.splice(index, 1);
    },
    handleTableBtnClick2({ index }) {
      this.node.lookUsers.splice(index, 1);
    },

    typeFormat(type) {
      switch (type) {
        case "1":
          return this.$t("岗位");
        case "2":
          return this.$t("角色");
        case "3":
          return this.$t("用户");
        case "4":
          return this.$t("上下级");
        case "5":
          return this.$t("节点");
        case "6":
          return this.$t("表字段");
        case "10":
          return this.$t("第三方");
      }
    },
    addTableData(selectData) {
      if (this.isLooker) {
        let addData2 = selectData.filter(
          (t) =>
            this.node.lookUsers.findIndex(
              (t2) => t2.id == t.id && t2.type == t.type
            ) == -1
        );
        this.node.lookUsers = this.node.lookUsers.concat(addData2);
      } else if (this.isAuditor) {
        let addData = selectData.filter(
          (t) =>
            this.node.auditUsers.findIndex(
              (t2) => t2.id == t.id && t2.type == t.type
            ) == -1
        );
        this.node.auditUsers = this.node.auditUsers.concat(addData);
      }
    },
    handleClickType(type){
      this.isLooker = false;
      this.isPointer = false;
      this.isAuditor = false;
      if (type == 'looker') this.isLooker = true
      else if (type == 'auditor') this.isAuditor = true
      else if (type == 'pointer') this.isPointer = true
    },
    handlePostClick(type) {
      this.selectPostVisible = true;
      this.handleClickType(type)
    },
    handlePostSelectClosed() {
      this.$refs.postSelectPanel.resetForm();
    },
    async handlePostSelectOk() {
      let postList = await this.$refs.postSelectPanel.getForm();
      let selectData = postList.map((t) => {
        return { type: "1", id: t.f_PostId, name: t.name };
      });
      this.addTableData(selectData);
      this.selectPostVisible = false;
    },

    handleRoleClick(type) {
      this.selectRoleVisible = true;
      this.handleClickType(type)
    },
    handleRoleSelectClosed() {
      this.$refs.roleSelectPanel.resetForm();
    },
    async handleRoleSelectOk() {
      let select = await this.$refs.roleSelectPanel.getForm();
      let selectData = select.map((t) => {
        return { type: "2", id: t.f_RoleId, name: t.f_FullName, condition: "" };
      });
      this.addTableData(selectData);
      this.selectRoleVisible = false;
    },

    handleUserClick(type) {
      this.selectUserVisible = true;
      this.handleClickType(type)
    },
    handleUserSelectClosed() {
      this.$refs.userSelectPanel.resetForm();
    },
    async handleUserSelectOk() {
      let select = await this.$refs.userSelectPanel.getForm();
      let selectData = select.map((t) => {
        return { type: "3", id: t.f_UserId, name: t.name };
      });
      this.addTableData(selectData);
      this.selectUserVisible = false;
    },

    handleLevelClick(type) {
      this.levelVisible = true;
      this.handleClickType(type)
    },
    handleLevelClosed() {
      this.$refs.auditorLevelForm.resetForm();
    },
    handleLevelOk() {
      this.$refs.auditorLevelForm.validateForm(() => {
        let data = this.$refs.auditorLevelForm.getForm();
        this.addTableData([data]);
        this.levelVisible = false;
      });
    },

    handleNodeAuditorClick(type) {
      this.nodeAuditorVisible = true;
      this.handleClickType(type)
    },
    handleNodeAuditorOk() {
      this.$refs.nodeAuditorForm.validateForm(() => {
        let data = this.$refs.nodeAuditorForm.getForm();
        this.addTableData([data]);
        this.nodeAuditorVisible = false;
      });
    },
    handleNodeAuditorClosed() {
      this.$refs.nodeAuditorForm.resetForm();
    },
    handleNodeAuditorOpened() {
      let wfdata = this.wfdesign.handleGetWFData();
      this.$refs.nodeAuditorForm.setForm(
        wfdata.filter((t) => (t.type = "userTask" && t.id != this.node.id))
      );
    },

    handleAuditorSqlClick(type) {
      this.auditorSqlVisible = true;
      this.handleClickType(type)
    },
    handleAuditorSqlOk() {
      this.$refs.auditorSqlForm.validateForm(() => {
        let data = this.$refs.auditorSqlForm.getForm();
        data.name = `${data.table}【${data.auditorField}】`;
        this.addTableData([data]);
        this.auditorSqlVisible = false;
      });
    },
    handleAuditorSqlClosed() {
      this.$refs.auditorSqlForm.resetForm();
    },

    // 第三方接口（iwork对接）客户可以按此处修改对接
    handleAuditorOtherAPIClick(type) {
      this.auditorOtherAPIVisible = true;
      this.handleClickType(type)
    },
    handleAuditorOtherAPIOk() {
      this.$refs.auditorOtherAPIForm.validateForm(() => {
        let data = this.$refs.auditorOtherAPIForm.getForm();
        console.log(data, "data");
        this.addTableData([data]);
        this.auditorOtherAPIVisible = false;
      });
    },
    async handleAuditorOtherAPIOpened(showloading, hideloading) {
      showloading("加载选项数据...");
      const list = await this.$awaitWraper(apiWFScheme.getAuditorsByOtherApi());
      this.$refs.auditorOtherAPIForm.init(list);
      hideloading();
    },
    handleAuditorOtherAPIClosed() {
      this.$refs.auditorOtherAPIForm.resetForm();
    },

    hasBtnsDeleteBtn(row) {
      if (row.isSys) {
        return false;
      } else {
        return true;
      }
    },
    handleAddBtns() {
      this.node.btnlist.push({
        code: "",
        name: "",
        hidden: false,
        isNextAuditor: false,
        isSign: false,
      });
    },
    handleDeleteBtns(row) {
      this.node.btnlist.splice(row.index, 1);
    },
    filterDeleteBtn(row){
      return !row.isSys;
    },
    countersignChange(){
      if(this.node.isCountersign){
        this.node.btnlist = this.node.btnlist.filter(t=>t.isSys);
      }
    }
  },
};
</script>

<style>
.wf-collapse-form .el-collapse-item__header {
  padding-left: 8px;
}
</style>
